package com.collectplus.express.logic;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.ImageView;

import com.collectplus.express.model.BagBean;
import com.collectplus.express.model.Const;
import com.collectplus.express.model.LocationBean;
import com.collectplus.express.model.OrderAppointBean;
import com.collectplus.express.model.ReceiverBean;
import com.collectplus.express.model.SameCityParcelBean;
import com.collectplus.express.model.SenderBean;
import com.collectplus.express.model.ServicePointBean;
import com.collectplus.express.model.UserBean;
import com.collectplus.express.model.VisitDoorBean;
import com.collectplus.express.tools.SharedPref;
import com.collectplus.express.wxapi.Constants;
import com.shouhuobao.bhi.msgnotice.MsgNoticeActivity;

import org.json.JSONObject;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

import droid.frame.App;
import droid.frame.Config;
import droid.frame.activity.HandlerMgr;
import droid.frame.utils.android.Log;
import droid.frame.utils.http.BitmapUtils;
import droid.frame.utils.http.HttpCallback;
import droid.frame.utils.http.HttpClient;
import droid.frame.utils.http.HttpLoader;
import droid.frame.utils.http.HttpParam;
import droid.frame.utils.http.HttpReq;
import droid.frame.utils.lang.Str;
import droid.frame.utils.rsa.DesUtil;

/**
 * {@link AppConfig}
 *
 * @author coffee<br>
 * 2015-10-13下午2:07:54
 */
public class AppHttp {

    private final String PAGE_SIZE = "500";

    private static AppHttp instance;

    private String versionCode = null;

    public static AppHttp getInstance() {
        if (instance == null) {
            instance = new AppHttp();
        }
        return instance;
    }

    private String getVersion() {
        if (versionCode != null) {
            return versionCode;
        }
        Context context = App.getContext();
        PackageManager packageManager = context.getPackageManager();
        // getPackageName()是你当前类的包名，0代表是获取版本信息
        try {
            PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
            versionCode = packInfo.versionCode + "";
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        return versionCode;
    }

    private String getServerUrl() {
        return AppConfig.getServerUrl();
    }

    private HashMap<String, Object> getMap() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("version", getVersion());
        map.put("device", "1");
        map.put(HttpParam.postText, true);
        map.put(HttpParam.toastNet, true);
        return map;
    }

    /**
     * @param url          传入绝对路径
     * @param isCheckLocal 是否检查本地缓存
     * @param imageView
     */
    public void loadImage(final String url, final ImageView imageView, final boolean isCheckLocal) {
        if (imageView == null) {
            Log.w("app:logic", "imageview为空, url不予请求", null);
            return;
        }
        // 头像
        new AsyncTask<Void, Void, Bitmap>() {
            @Override
            protected Bitmap doInBackground(Void... params) {
                // 头像
                Bitmap image = BitmapUtils.loadBitmapFromNet(url, isCheckLocal);
                return image;
            }

            @Override
            protected void onPostExecute(Bitmap result) {
                if (result != null && imageView != null) {
                    imageView.setImageBitmap(result);
                }
            }
        }.execute();
    }

    /**
     * 启动的时候调用, 获取APP的配置信息
     *
     * @param context
     */
    public void getAppConfig(Activity context) {
        DisplayMetrics dm = new DisplayMetrics();
        context.getWindowManager().getDefaultDisplay().getMetrics(dm);
        int screenWidth = dm.widthPixels;
        int screenHeight = dm.heightPixels;

        Map<String, Object> map = getMap();
        // map.put("id", id);
        map.put("width", screenWidth);
        map.put("height", screenHeight);
        // map.put(HttpParam.cache, true);
        int userId = AppCache.getUserId();
        if (userId != 0) {
            map.put("userId", userId);
        }
        // int shbUserId = AppCache.getShbUserId();
        // if (shbUserId != 0) {
        // map.put("shbUserId", shbUserId);
        // }
        map.put(HttpParam.cache, false);// add cache

        HttpReq req = new HttpReq(map, MsgID.get_appConfig);
        req.setUrl(getServerUrl() + "index");
        HttpLoader.getInstance().sendReq(req);
    }

    public void mapGeoconv(double latitude, double longitude) {
        HashMap<String, Object> datas = new HashMap<String, Object>();
        datas.put("coords", latitude + "," + longitude);
        datas.put("from", "5");
        datas.put("to", "6");
        datas.put("ak", "yfPWHPcmNlZFlVDkR2jcF6lY");
        datas.put(HttpParam.postText, true);
        datas.put(HttpParam.toastNet, true);
        HttpReq req = new HttpReq(datas, MsgID.map_geoconv);
        req.setUrl("http://api.map.baidu.com/geoconv/v1/");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取短信验证码
     *
     * @param phone
     */
    public void loginSMSVerifyNum(String phone, Integer codeType) {
        Map<String, Object> map = getMap();
        map.put("phone", phone);
        map.put("timestamp", System.currentTimeMillis());
        if (null != codeType) {
            map.put("smsType", codeType);
        }
        JSONObject jsonObject = new JSONObject(map);
        String data = DesUtil.ebotongEncrypto(jsonObject.toString());
        map.put("sendInfo", data);
        HttpReq req = new HttpReq(map, MsgID.send_verifyNum);
//        req.setUrl(getServerUrl() + "sendVerifyCode");//sendVerificationCode
        req.setUrl(getServerUrl() + "sendVerifyCodeDes");//sendVerificationCode
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取短信验证码
     *
     * @param phone
     */
    //    public void loginSMSVerifyNum(String phone, String code, String codeType) {
    //        Map<String, Object> map = getMap();
    //        map.put("phone", phone);
    //        map.put("imageCode", code);
    //        if (!Str.isEmpty(codeType)) {
    //            map.put("smsType", codeType);
    //        }
    //        HttpReq req = new HttpReq(map, MsgID.send_verifyNum);
    //        req.setUrl(getServerUrl() + "sendVerifyCode2");//sendVerificationCode
    //        HttpLoader.getInstance().sendReq(req);
    //    }

    /**
     * 语音验证码
     *
     * @param phone
     */
    public void loginSoundVerifyNum(String phone) {
        Map<String, Object> map = getMap();
        map.put("phone", phone);

        HttpReq req = new HttpReq(map, MsgID.send_SoundVerifyNum);
        req.setUrl(getServerUrl() + "sendSoundVerifyCode");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 语音验证码
     *
     * @param phone
     */
    //    public void loginSoundVerifyNum(String phone, String code) {
    //        Map<String, Object> map = getMap();
    //        map.put("phone", phone);
    //        map.put("imageCode", code);
    //        HttpReq req = new HttpReq(map, MsgID.send_SoundVerifyNum);
    //        req.setUrl(getServerUrl() + "sendSoundVerifyCode2");
    //        HttpLoader.getInstance().sendReq(req);
    //    }

    /**
     * 登录、确认验证码
     *
     * @param phone
     */
    public void confirmVerifyNum(String phone, String code) {
        Map<String, Object> map = getMap();
        map.put("phone", phone);
        map.put("verifyCode", code);
        HttpReq req = new HttpReq(map, MsgID.confirmVerifyNum);
        req.setUrl(getServerUrl() + "confirmVerifyCode");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 检测投递袋是否合法
     *
     * @param bagCode
     */
    public void selfBagCodeCheck(String bagCode) {
        Map<String, Object> map = getMap();
        map.put("bagNo", bagCode);
        //
        HttpReq req = new HttpReq(map, MsgID.self_bagcode_check);
        req.setUrl(getServerUrl() + "bag/validateBagNo");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取附近的的智能柜列表
     *
     * @param lng
     *            经度
     * @param lat
     *            维度
     */
    // public void cabinetGetNearby(double longitude, double latitude) {
    // Map<String, Object> map = getMap();
    // map.put("longitude", longitude);
    // map.put("latitude", latitude);
    // //
    // HttpReq req = new HttpReq(map, MsgID.self_cabinet_nearby_getlist);
    // req.setUrl(getServerUrl() + "box/getClosetBoxes");
    // HttpLoader.getInstance().sendReq(req);
    // }

    /**
     * 获取附近的的智能柜、驿站
     *
     * @param longitude 经度
     * @param latitude  维度
     */
    public void cabinetGetNearby2(double longitude, double latitude) {
        Map<String, Object> map = getMap();
        UserBean user = AppCache.getUser();
        map.put("longitude", longitude);
        map.put("latitude", latitude);
        if (user != null) {
            map.put("userId", user.getId());
        }
        //
        HttpReq req = new HttpReq(map, MsgID.self_cabinet_nearby_alls);
        // req.setUrl(getServerUrl() + "postStation/orderPostStation360");
        req.setUrl(getServerUrl() + "station/orderStation380");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取指定的智能柜的可用状态
     */
    public void cabinetGetState(String deviceId) {
        Map<String, Object> map = getMap();
        map.put("stationCode", deviceId);
        //
        HttpReq req = new HttpReq(map, MsgID.self_cabinet_usableState_get);
        req.setUrl(getServerUrl() + "box/queryBoxStatus");
        // req.setArg1(deviceId);
        HttpLoader.getInstance().sendReq(req);
    }

    public void saveAddress(String communityName, String address, String longitude, String latitude, String x, String y) {
        int id = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("id", id);
        map.put("communityName", communityName);
        map.put("address", address);
        map.put("longitude", longitude);
        map.put("latitude", latitude);
        map.put("x", x);
        map.put("y", y);

        HttpReq req = new HttpReq(map, MsgID.save_address);
        req.setUrl(getServerUrl() + "saveAddress");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 标准上门下单前查询订单状态，有未完成的订单就提示
     */
    public void orderGoHomeAvaliable() {
        Map<String, Object> map = getMap();
        int id = AppCache.getUserId();
        map.put("userId", id);

        HttpReq req = new HttpReq(map, MsgID.order_goHome_avaliable);
        req.setUrl(getServerUrl() + "queryUnPayOrderCount");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取订单可以预约的时间
     */
    public void orderReserve(LocationBean location) {
        int id = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("id", id);
        map.put("communityName", location.getName1());
        map.put("address", location.getAddress());
        map.put("longitude", location.getLongitude());
        map.put("latitude", location.getLatitude());
        map.put("x", location.getX());
        map.put("y", location.getY());

        HttpReq req = new HttpReq(map, MsgID.order_reserve);
        req.setUrl(getServerUrl() + "reserveOrder");
        HttpLoader.getInstance().sendReq(req);
    }

    private HashMap<String, Object> getOrderMap(LocationBean location, OrderAppointBean orderAppoint) {
        UserBean user = AppCache.getUser();
        HashMap<String, Object> map = getMap();
        //收件人信息
        ReceiverBean item = AppCache.getParcelNew();
        ServicePointBean box = item.getServicePoint();
        map.put("userId", user.getId());

        // 自助寄件
        if (box != null) {
            map.put("payType", box.getSubmitPayType());
            map.put("deviceId", box.getId());
            if (Const.ParcelType.visitToHome == box.getType() || Const.ParcelType.bagToHome == box.getType()) {
                map.put("phone", user.getPhone());
            } else {
                map.put("senderPhone", user.getPhone());
            }
        }
        StringBuilder sb = new StringBuilder();
        sb.append("{");// 最外层{start
        sb.append("'source':1,");
        sb.append("'userId':'").append(user.getId()).append("',");
        sb.append("'phone':'").append(user.getPhone()).append("',");
        // sb.append("'payType':'").append(box.getSubmitPayType()).append("',");
        if (box != null) {
            sb.append("'stationId':'").append(box.getId()).append("',");
        }
        sb.append("'expressCompanyId':'").append(item.getExpressCompanyId()).append("',");
        sb.append("'expressCompanyName':'").append(item.getExpressCompanyName()).append("',");
        // 俩字段都为空 说明是到柜、或者到驿站、否则是有袋上门
        if (location == null && orderAppoint == null) {
            if (item.getServicePoint() != null) {
                if (Const.ParcelType.bagToHome == item.getServicePoint().getType()) {
                    item.setType(3);// 到驿站
                } else if (Const.ParcelType.visitToHome == item.getServicePoint().getType()) {
                    item.setType(Const.ParcelType.visitToHome);// 上门
                } else {
                    item.setType(1);// 到柜
                }
            }
        } else {
            item.setType(2);// 有袋上门
        }
        // 寄件类型 -- // 0：标准 1：有袋到柜 2：有袋上门 3:有袋到店，驿站
        sb.append("'parcelType':").append(item.getType()).append(",");
        // 标准寄件
        if (orderAppoint != null) {
            // 不为空, 则说明是订单预约
            if ("现在".equals(orderAppoint.getText()) == false) {
                sb.append("'isImmediate':'").append(2).append("',");
            } else {
                sb.append("'isImmediate':'").append(1).append("',");
                // sb.append("'dutyRosterId':'").append(appoint.getId()).append("',");
            }
            sb.append("'dutyRosterId':'").append(orderAppoint.getId()).append("',");
            sb.append("'serviceTimeGe':").append(orderAppoint.getServiceTimeGe()).append(",");
            sb.append("'serviceTimeLe':").append(orderAppoint.getServiceTimeLe()).append(",");
        }
        // 有袋上门
        if (location != null) {
            sb.append("'address':");
            sb.append("{");
            if (location.getId() != 0) {
                sb.append("'id':").append(location.getId()).append("");
            } else {
                sb.append("'userId':").append(user.getId()).append(",");
                sb.append("'name':'").append(location.getAddress()).append("',");
                sb.append("'latitude':'").append(location.getLatitude()).append("',");
                sb.append("'longitude':'").append(location.getLongitude()).append("',");
                sb.append("'x':'").append(location.getX()).append("',");
                sb.append("'y':'").append(location.getY()).append("'");
            }
            sb.append("},");// 注意后面的逗号
        }

        //
        sb.append("'parcels':");
        sb.append("[");// receivers start
        sb.append("{");
        if (item.getId() != 0) {
            sb.append("'receiverId':").append(item.getId()).append(",");
        }
        if (box != null) {// 智能柜添加参数
            sb.append("'stationId':'").append(box.getId()).append("',");
            sb.append("'stationCode':'").append(box.getCode()).append("',");
            sb.append("'boxType':'").append(box.getSize()).append("',");
        }
        sb.append("'receiverName':'").append(item.getName()).append("',");
        sb.append("'receiverPhone':'").append(item.getPhone()).append("',");
        sb.append("'receiverAddress':'").append(item.getAddress()).append("',");
        //
        sb.append("'receiverProvince':'").append(item.getProvince()).append("',");
        sb.append("'receiverProvinceId':'").append(item.getProvinceId()).append("',");
        sb.append("'receiverCity':'").append(item.getCity()).append("',");
        sb.append("'receiverCityId':'").append(item.getCityId()).append("',");
        sb.append("'receiverDistrict':'").append(item.getDistrict()).append("',");
        sb.append("'receiverDistrictId':'").append(item.getDistrictId()).append("',");
        //
        sb.append("'receiverProvinceId':").append(item.getProvinceId()).append(",");
        sb.append("'receiverCityId':").append(item.getCityId()).append(",");
        sb.append("'receiverDistrictId':").append(item.getDistrictId()).append(",");
        //
        sb.append("'expressCompanyId':").append(item.getExpressCompanyId()).append(",");
        sb.append("'expressCompanyName':'").append(item.getExpressCompanyName()).append("',");
        sb.append("'weight':'").append(item.getWeight()).append("',");
        sb.append("'cost':'").append(item.getExpressPrice()).append("',");
        sb.append("'comment':'").append(item.getRemark()).append("',");
        // sb.append("'parcelName':'").append(item.getGoodsName()).append("',");
        // sb.append("'parcelValue':'").append(item.getGoodsValue()).append("',");
        sb.append("'parcelImgUrl':'").append(item.getParcelImgUrl()).append("',");
        // 处理投递袋
        if (item.getBag() != null) {
            BagBean bag = item.getBag();
            sb.append("'bagCode':'").append(bag.getCode()).append("',");
        }
        if (item.getSender() != null) {
            SenderBean sender = item.getSender();
            sb.append("'userName':'").append(sender.getName()).append("',");
            sb.append("'senderId':'").append(sender.getId()).append("',");
            sb.append("'userPhone':'").append(sender.getPhone()).append("',");
            sb.append("'userAddress':'").append(sender.getAddress()).append("',");
            //
            sb.append("'userProvince':'").append(sender.getProvince()).append("',");
            sb.append("'userProvinceId':'").append(sender.getProvinceId()).append("',");
            sb.append("'userCity':'").append(sender.getCity()).append("',");
            sb.append("'userCityId':'").append(sender.getCityId()).append("',");
            sb.append("'userDistrict':'").append(sender.getDistrict()).append("',");
            sb.append("'userDistrictId':'").append(sender.getDistrictId()).append("',");
        }
        //
        // sb.append("'parcelType':").append(item.getType()).append(",");
        // 自助寄件|有袋上门 都传入以下参数、有的参数没用
        if (box != null) {
            // 只有驿站的时候需要添加一下驿站id
            if (Const.ParcelType.bagToHome == box.getType()) {
                sb.append("'stationId':").append(box.getId()).append(",");
            } else {
                sb.append("'boxId':").append(box.getId()).append(",");
                // sb.append("'boxCode':'").append(box.getCode()).append("',");
                sb.append("'boxAddress':'").append(box.getAddress()).append("',");
            }
            sb.append("'category':'").append(box.getGoodsType()).append("'");
        }
        sb.append("}");
        sb.append("]");// receivers end
        sb.append(",");// 注意后面的逗号
        //上门寄件的信息
        sb.append("'visit':");
        sb.append("{");
        VisitDoorBean visitDoorBean = item.getVisitDoorBean();
        if (null != visitDoorBean) {
            //            VisitDoorBean doorBean = new VisitDoorBean();
            //            doorBean.setProvince("北京市");
            //            doorBean.setCity("北京市");
            //            doorBean.setDistrict("昌平区");
            //            doorBean.setLatitude(40.0724841731);
            //            doorBean.setLongitude(116.4288823131);
            //            VisitDoorBean doorBean1 = new VisitDoorBean();
            //            doorBean1.setProvince("北京市");
            //            doorBean1.setCity("北京市");
            //            doorBean1.setDistrict("昌平区");
            //            doorBean1.setLatitude(40.0784804931);
            //            doorBean1.setLongitude(116.3434200014);
            //            VisitDoorBean[] doorBeans = new VisitDoorBean[]{doorBean,doorBean1};
            //            Random random = new Random();
            //            int i = random.nextInt(2);
            sb.append("'buildName':'").append(visitDoorBean.getBuildName()).append("',");
            sb.append("'address':'").append(visitDoorBean.getAddress() + visitDoorBean.getAddressDesc()).append("',");
            sb.append("'latitude':'").append(visitDoorBean.getLatitude()).append("',");
            sb.append("'longitude':'").append(visitDoorBean.getLongitude()).append("',");
            //            sb.append("'latitude':'").append(doorBeans[i].getLatitude()).append("',");
            //            sb.append("'longitude':'").append(doorBeans[i].getLongitude()).append("',");
            sb.append("'addressDesc':'").append(visitDoorBean.getAddressDesc()).append("',");
            sb.append("'phone':'").append(visitDoorBean.getPhone()).append("',");
            sb.append("'province':'").append(visitDoorBean.getProvince()).append("',");
            sb.append("'city':'").append(visitDoorBean.getCity()).append("',");
            sb.append("'district':'").append(visitDoorBean.getDistrict()).append("'");
            //            sb.append("'province':'").append(doorBeans[i].getProvince()).append("',");
            //            sb.append("'city':'").append(doorBeans[i].getCity()).append("',");
            //            sb.append("'district':'").append(doorBeans[i].getDistrict()).append("'");
        }
        sb.append("}");//上门寄件end

        sb.append("}");// 最外层}end
        // 过滤掉 'null'字符串 、
        String data = sb.toString().replace("'null'", "null").replace("'", "\"");
        map.put("data", data);
        return map;
    }

    /**
     * 上传图片
     *
     * @param imageUrl
     */
    public void orderImageUpdate(String imageUrl) {
        new AsyncTask<String, Void, String>() {
            @Override
            protected String doInBackground(String... params) {
                File file = new File(params[0]);
                String result = "";
                if (AppConfig.isTest) {// 测试环境
                    result = HttpClient.postFile("http://files.shouhuobao.com:8080/fileUpload/fileUpload/test", file);
                } else {
                    result = HttpClient.postFile("http://files.shouhuobao.com:8080/fileUpload/fileUpload/product", file);
                }
                return result;
            }

            protected void onPostExecute(String result) {
                HandlerMgr.sendMessage(MsgID.order_upload_image, result);
            }
        }.execute(imageUrl);
    }

    /**
     * 上传多张图片
     */
    public void postFils(String... imageUrl) {
        new AsyncTask<String, Void, String>() {
            @Override
            protected String doInBackground(String... params) {
                return HttpClient.postFiles(AppConfig.getFileUrl(), params);
            }

            protected void onPostExecute(String result) {
                HandlerMgr.sendMessage(MsgID.order_upload_image, result);
            }
        }.execute(imageUrl);
    }

    /**
     * 投递袋自助|寄件
     *
     * @param location 自助寄件传null, 有袋上门传入location
     */
    public void orderWithBag(LocationBean location, OrderAppointBean appoint) {
        HashMap<String, Object> map = getOrderMap(location, appoint);
        HttpReq req = new HttpReq(map, MsgID.order_new);
        // 有袋上门
        if (location != null) {
            req.setUrl(getServerUrl() + "reserveOrderBag");
        } else {
            req.setUrl(getServerUrl() + "reserveOrder360");
        }
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 上门取件下单
     */
    public void bagToHome(LocationBean location, OrderAppointBean appoint) {
        HashMap<String, Object> map = getOrderMap(location, appoint);
        HttpReq req = new HttpReq(map, MsgID.order_new);
        // 有袋上门
        req.setUrl(getServerUrl() + "reserveOrder2Courier");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 投递袋自助|寄件 智能柜
     *
     * @param location 自助寄件传null, 有袋上门传入location
     */
    public void orderWithBox(LocationBean location, OrderAppointBean appoint) {
        HashMap<String, Object> map = getOrderMap(location, appoint);
        HttpReq req = new HttpReq(map, MsgID.order_new);
        // 有袋上门
        if (location != null) {
            req.setUrl(getServerUrl() + "reserveOrderBag");
        } else {
            req.setUrl(getServerUrl() + "reserveOrder2Box");
        }
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 邮票下单
     *
     * @param stampSids 邮票id
     */
    public void stampOrder(String stampSids) {
        HashMap<String, Object> map = getMap();
        UserBean user = AppCache.getUser();
        map.put("userId", user.getId());
        map.put("stampSid", stampSids);
        HttpReq req = new HttpReq(map, MsgID.stamp_order);
        req.setUrl(getServerUrl() + "orderStamp/submit");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 投递袋自助、重新获取开箱码
     *
     * @param orderId 自助寄件传null, 有袋上门传入location
     */
    public void orderRequestBoxCode(String orderId) {
        UserBean user = AppCache.getUser();
        HashMap<String, Object> map = getMap();
        map.put("userId", user.getId());
        map.put("phone", user.getPhone());
        map.put("data", "{\"retry\":true}");
        map.put("orderId", orderId);
        HttpReq req = new HttpReq(map, MsgID.passport_code_again);
        req.setUrl(getServerUrl() + "reserveOrderWithBox");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 下单
     *
     * @return 返回是否是立即下单 true 预约 false
     */
    public boolean order(LocationBean location, OrderAppointBean orderAppoint) {
        UserBean user = AppCache.getUser();
        Map<String, Object> map = getMap();
        map.put("userId", user.getId());
        map.put("phone", user.getPhone());
        StringBuilder sb = new StringBuilder();

        sb.append("{");
        sb.append("'source':1,");
        sb.append("'userId':'").append(user.getId()).append("',");
        sb.append("'phone':'").append(user.getPhone()).append("',");
        boolean result = true;
        // 不为空, 则说明是订单预约
        if (orderAppoint != null && "现在".equals(orderAppoint.getText()) == false) {
            sb.append("'isImmediate':'").append(2).append("',");
            result = false;//
        } else {
            sb.append("'isImmediate':'").append(1).append("',");
            // sb.append("'dutyRosterId':'").append(appoint.getId()).append("',");
        }
        sb.append("'dutyRosterId':'").append(orderAppoint.getId()).append("',");
        sb.append("'serviceTimeGe':").append(orderAppoint.getServiceTimeGe()).append(",");
        sb.append("'serviceTimeLe':").append(orderAppoint.getServiceTimeLe()).append(",");
        // 普通上门、
        sb.append("'parcelType':").append(0).append(",");

        sb.append("'receivers':");
        sb.append("[");
        ReceiverBean item = AppCache.getParcelNew();
        sb.append("{");
        if (item.getId() != 0) {
            sb.append("'id':").append(item.getId()).append(",");
        }
        sb.append("'name':'").append(item.getName()).append("',");
        sb.append("'phone':'").append(item.getPhone()).append("',");
        sb.append("'address':'").append(item.getAddress()).append("',");
        sb.append("'provinceId':").append(item.getProvinceId()).append(",");
        sb.append("'cityId':").append(item.getCityId()).append(",");
        sb.append("'districtId':").append(item.getDistrictId()).append(",");
        sb.append("'expressCompanyId':").append(item.getExpressCompanyId()).append(",");
        sb.append("'expressCompanyName':'").append(item.getExpressCompanyName()).append("',");
        sb.append("'weight':'").append(item.getWeight()).append("',");
        sb.append("'cost':'").append(item.getExpressPrice()).append("',");
        sb.append("'comment':'").append(item.getRemark()).append("',");
        sb.append("'parcelName':'").append(item.getGoodsName()).append("',");
        sb.append("'parcelValue':'").append(item.getGoodsValue()).append("',");
        sb.append("'parcelImgUrl':'").append(item.getParcelImgUrl()).append("'");

        sb.append("}");
        sb.append("],");

        sb.append("'address':");
        sb.append("{");
        if (location.getId() != 0) {
            sb.append("'id':").append(location.getId()).append("");
        } else {
            sb.append("'userId':").append(user.getId()).append(",");
            sb.append("'name':'").append(location.getAddress()).append("',");
            sb.append("'latitude':'").append(location.getLatitude()).append("',");
            sb.append("'longitude':'").append(location.getLongitude()).append("',");
            sb.append("'x':'").append(location.getX()).append("',");
            sb.append("'y':'").append(location.getY()).append("'");
        }
        sb.append("}");
        sb.append("}");
        map.put("data", sb.toString());

        HttpReq req = new HttpReq(map, MsgID.order_new);
        req.setUrl(getServerUrl() + "order");
        HttpLoader.getInstance().sendReq(req);
        return result;
    }

    /**
     * 可以传入int 或者 string
     *
     * @param orderId
     */
    //    public void orderDetail(Serializable orderId) {
    //        Map<String, Object> map = getMap();
    //        map.put("orderId", orderId);
    //
    //        HttpReq req = new HttpReq(map, MsgID.order_detail);
    //        req.setUrl(getServerUrl() + "showOrder");
    //        HttpLoader.getInstance().sendReq(req);
    //    }
    public void orderDetail(Serializable orderId) {
        Map<String, Object> map = getMap();
        map.put("orderId", orderId);

        HttpReq req = new HttpReq(map, MsgID.order_detail);
        req.setUrl(getServerUrl() + "order/show");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 订单取消
     *
     * @param orderId
     */
    public void orderCancel(Serializable orderId, Serializable parcelId, int reasonId, String content) {
        Map<String, Object> map = getMap();
        map.put("orderId", orderId);
        map.put("openIdType", -1);
        map.put("parcelId", parcelId);
        map.put("reasonId", reasonId);
        map.put("content", content);
        HttpReq req = new HttpReq(map, MsgID.order_cancel);
        req.setUrl(getServerUrl() + "order/cancelOrder2");
        HttpLoader.getInstance().sendReq(req);
    }

    // /**
    // * 从历史记录添加包裹
    // */
    // public void saveReceiverFromHistory(int orderId, String receiverIds) {
    // int userId = AppCache.getUserId();
    // Map<String, Object> map = getMap();
    // map.put("userId", userId);
    // map.put("orderId", orderId);
    // //
    // HashMap<String, Object> dataMap = new HashMap<String, Object>();
    // dataMap.put("userId", userId);
    // dataMap.put("orderId", orderId);
    // dataMap.put("receiverId", receiverIds);// 多个包裹用逗号分隔
    //
    // String dataStr = JsonParser.toJson(dataMap);
    // map.put("data", dataStr);
    //
    // HttpReq req = new HttpReq(map, MsgID.receiver_add_from_history);
    // req.setUrl(getServerUrl() + "saveParcel");
    // HttpLoader.getInstance().sendReq(req);
    // }

    /**
     * 修改收件人
     *
     * @param receiverId 收件人ID
     */
    public void receiverEditOld(int receiverId, String name,//
                                String phone, String provinceId, String cityId, String districtId, String address) {
        Map<String, Object> map = getMap();
        map.put("id", receiverId);// 收件人ID
        map.put("name", name);
        map.put("phone", phone);
        map.put("provinceId", provinceId);
        map.put("cityId", cityId);
        map.put("districtId", districtId);
        map.put("address", address);

        HttpReq req = new HttpReq(map, MsgID.receiverEdit);
        req.setUrl(getServerUrl() + "editReceiver");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取寄件人/收件人列表
     * addType:地址类型1：收件，2：寄件
     *
     * @param pageNum 当前第几页
     */
    public void senderList(int pageNum, int addType) {
        int userId = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("userId", userId);
        map.put("pageNum", pageNum);
        map.put("pageSize", PAGE_SIZE);
        map.put("addType", addType);
        HttpReq req = new HttpReq(map, MsgID.senderList);
        req.setUrl(getServerUrl() + "listNewReceiver");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 从最近常用联系人列表中 ---- 删除联系人
     *
     * @param receiverId
     */
    public void receiverDeleteFromHistory(int receiverId, int position) {
        int userId = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("userId", userId);// 用户ID
        map.put("receiverId", receiverId);// 收寄件ID
        HttpReq req = new HttpReq(map, MsgID.receiver_Delete_from_history);
        req.setUrl(getServerUrl() + "receiver/delete");
        req.setArg1(position);
        HttpLoader.getInstance().sendReq(req);
    }


    public void listParcel(int pageNum) {
        int userId = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("pageSize", PAGE_SIZE);
        map.put("userId", userId);
        map.put("pageNum", pageNum);

        HttpReq req = new HttpReq(map, MsgID.listParcel);
        req.setUrl(getServerUrl() + "listParcel");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 查看包裹详情、包括路由信息
     *
     * @param id
     */
    public void showParcel(String id) {
        Map<String, Object> map = getMap();
        map.put("id", id);

        HttpReq req = new HttpReq(map, MsgID.showParcel);
        req.setUrl(getServerUrl() + "showParcel");
        HttpLoader.getInstance().sendReq(req);
    }

    public void profile() {
        int userId = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("userId", userId);
        HttpReq req = new HttpReq(map, MsgID.profile);
        req.setUrl(getServerUrl() + "profile");
        HttpLoader.getInstance().sendReq(req);
    }

    public void checkUpdate() {
        int userId = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("userId", userId);

        HttpReq req = new HttpReq(map, MsgID.checkUpdate);
        req.setUrl(getServerUrl() + "checkUpdate");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * @param orderId
     * @param realCost  实际支付价格
     * @param cost      订单价格
     * @param couponsId
     * @param isCover   是否是补差价
     */
    public void weiXinPay(int orderId, String realCost, String cost, int couponsId, int isCover) {
        int userId = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("orderId", orderId);
        map.put("userId", userId);
        map.put("cost", cost);
        map.put("realCost", realCost);
        map.put("openIdType", -1);
        if (couponsId != 0) {
            map.put("couponsId", couponsId);// 邮票
        }
        //
        HttpReq req = new HttpReq(map, MsgID.weiXinPay);
        if (isCover == 1) {
            req.setUrl(getServerUrl() + "payParcel2/wxPay");
        } else {
            req.setUrl(getServerUrl() + "payParcel/wxPay");
        }
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * @param orderId
     */
    public void stampPay(Object orderId, String stampOrderId) {
        int userId = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("orderId", orderId);
        map.put("stampOrderId", stampOrderId);
        map.put("userId", userId);
        HttpReq req = new HttpReq(map, MsgID.stamp_pay);
        req.setUrl(getServerUrl() + "payParcel/stampPay");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * @param orderId
     * @param realCost  实际支付价格
     * @param cost      订单价格
     * @param couponsId
     */
    public void stampWeiXinPay(int orderId, String realCost, String cost, int couponsId) {
        int userId = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("orderId", orderId);
        map.put("userId", userId);
        map.put("cost", cost);
        map.put("realCost", realCost);
        map.put("openIdType", -1);
        if (couponsId != 0) {
            map.put("couponsId", couponsId);// 邮票
        }
        //
        HttpReq req = new HttpReq(map, MsgID.stamp_wxpay);
        req.setUrl(getServerUrl() + "payStamp/wxPay");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 微信分享配置信息
     */
    public void weiXinShare(String orderId) {
        // int orderId = AppCache.getOrderId();
        Map<String, Object> map = getMap();
        map.put("orderId", orderId);
        //
        HttpReq req = new HttpReq(map, MsgID.weixin_share);
        req.setUrl(AppConfig.getServerWXUrl() + "getShareUrl");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * @param orderId
     * @param realCost  实际支付金额
     * @param cost
     * @param couponsId
     * @param couponsId 是否是补差价
     */
    public void aliPay(int orderId, String realCost, String cost, int couponsId, int isCover) {
        int userId = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("orderId", orderId);
        map.put("userId", userId);
        map.put("cost", cost);
        map.put("realCost", realCost);
        if (couponsId != 0) {
            map.put("couponsId", couponsId);// 邮票
        }
        HttpReq req = new HttpReq(map, MsgID.aliPay);
        if (isCover == 1) {
            req.setUrl(getServerUrl() + "payParcel2/aliPay");
        } else {
            req.setUrl(getServerUrl() + "payParcel/aliPay");
        }
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 支付宝
     *
     * @param orderId
     * @param realCost  实际支付金额
     * @param cost
     * @param couponsId
     */
    public void stampAliPay(int orderId, String realCost, String cost, int couponsId) {
        int userId = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("orderId", orderId);
        map.put("userId", userId);
        map.put("cost", cost);
        map.put("realCost", realCost);
        if (couponsId != 0) {
            map.put("couponsId", couponsId);// 邮票
        }
        HttpReq req = new HttpReq(map, MsgID.stamp_alipay);
        req.setUrl(getServerUrl() + "payStamp/aliPay");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * @param cuid      代收用户id
     * @param pointId   网点id
     * @param cost      应付金额
     * @param realCost  实付金额
     * @param pickWay   取货方式
     * @param couponsId 邮票id
     */
    public void aliPayForCollect(String cuid, String pointId, String cost, String realCost, String pickWay, int couponsId) {
        Map<String, Object> map = getMap();
        map.put("cuid", cuid);
        map.put("pointId", pointId);
        map.put("cost", cost);
        map.put("realCost", realCost);
        map.put("pickWay", pickWay);
        if (couponsId != 0) {
            map.put("couponsId", couponsId);// 邮票
        }
        HttpReq req = new HttpReq(map, MsgID.collect_aliPay);
        // req.setUrl(getServerUrl() + "collectAliPay");
        req.setUrl(getServerUrl() + "collectAliPayForCoupon");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * @param cuid      代收用户id
     * @param pointId   网点id
     * @param cost      应付金额
     * @param realCost  实付金额
     * @param pickWay   取货方式
     * @param couponsId 邮票id
     */
    public void weiXinPayForCollect(String cuid, String pointId, String cost, String realCost, String pickWay, int couponsId) {
        Map<String, Object> map = getMap();
        map.put("cuid", cuid);
        map.put("pointId", pointId);
        map.put("cost", cost);
        map.put("realCost", realCost);
        map.put("pickWay", pickWay);
        if (couponsId != 0) {
            map.put("couponsId", couponsId);// 邮票
        }
        //
        HttpReq req = new HttpReq(map, MsgID.collect_weiXinPay);
        // req.setUrl(getServerUrl() + "collectWeixinPay");
        req.setUrl(getServerUrl() + "collectWeixinPayForCoupon");
        HttpLoader.getInstance().sendReq(req);
    }

    // 现金支付，扫码取
    public void cashPayForCollectScan(String cuid, String pointId, String cost, String realCost, String pickWay, int couponsId) {
        Map<String, Object> map = getMap();
        map.put("cuid", cuid);
        map.put("pointId", pointId);
        // map.put("cost", cost);
        // map.put("realCost", realCost);
        // map.put("pickWay", pickWay);
        // if (couponsId != 0) {
        // map.put("couponsId", couponsId);// 邮票
        // }
        //
        HttpReq req = new HttpReq(map, MsgID.collect_cashPay);
        // req.setUrl(getServerUrl() + "collectWeixinPay");
        // TODO,URL地址需要修改
        req.setUrl(getServerUrl() + "scanPickByCash");
        HttpLoader.getInstance().sendReq(req);
    }

    // 现金支付，密码取
    public void cashPayForCollectPassword(String cuid, String pointId, String cost, String realCost, String pickWay, int couponsId) {
        Map<String, Object> map = getMap();
        map.put("cuid", cuid);
        map.put("pointId", pointId);
        // map.put("cost", cost);
        // map.put("realCost", realCost);
        // map.put("pickWay", pickWay);
        // if (couponsId != 0) {
        // map.put("couponsId", couponsId);// 邮票
        // }
        //
        HttpReq req = new HttpReq(map, MsgID.collect_cashPay);
        // req.setUrl(getServerUrl() + "collectWeixinPay");
        // TODO,URL地址需要修改
        req.setUrl(getServerUrl() + "pwdPickByCash");
        HttpLoader.getInstance().sendReq(req);
    }

    public void editUserName(String name) {
        int userId = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("id", userId);
        map.put("name", name);

        HttpReq req = new HttpReq(map, MsgID.editUserName);
        req.setUrl(getServerUrl() + "updateUserName");
        HttpLoader.getInstance().sendReq(req);
    }

    public void faq(String content) {
        int userId = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("userId", userId);
        map.put("content", content);

        HttpReq req = new HttpReq(map, MsgID.faq);
        req.setUrl(getServerUrl() + "opinion");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 支付成功的回调 -- 通知服务器修改状态
     *
     * @param orderId payType 微信为1  支付宝 2
     * @param isCover 1为补差价
     */
    public void orderPayCallBack(Object orderId, int payType, int isCover) {
        Map<String, Object> map = getMap();
        int userId = AppCache.getUserId();
        map.put("userId", userId);
        map.put("orderId", orderId);
        map.put("payType", payType);
        map.put("openIdType", -1);

        HttpReq req = new HttpReq(map, MsgID.wxPayCallback);
        if (isCover == 1) {
            req.setUrl(getServerUrl() + "payParce2/appPayReturn");
        } else {
            req.setUrl(getServerUrl() + "payParcel/appPayReturn");
        }
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 购买邮票支付成功的回调 -- 通知服务器修改状态
     *
     * @param orderId payType 微信为1
     */
    public void stampPayCallBack(int orderId, int payType, int isCover) {
        Map<String, Object> map = getMap();
        int userId = AppCache.getUserId();
        map.put("userId", userId);
        map.put("orderId", orderId);
        map.put("payType", payType);
        map.put("openIdType", -1);

        HttpReq req = new HttpReq(map, MsgID.wxPayCallback);
        if (isCover == 1) {
            req.setUrl(getServerUrl() + "payStamp2/appPayReturn");
        } else {
            req.setUrl(getServerUrl() + "payStamp/appPayReturn");
        }
        // req.setUrl(getServerUrl() + "weiXinPayReturn");
        HttpLoader.getInstance().sendReq(req);
    }

    // / aliPayReturn

    public void crashUpload() {
        try {
            final String uploadUrl = "http://test.guoer-jam.shouhuobao.com:8011/guoer-jam/crash/uploadCrash";
            new Thread(new Runnable() {
                @Override
                public void run() {
                    // /storage/emulated/0/shouhuobao/crash
                    String crashDir = Config.getCrashDir();
                    if (crashDir == null) {
                        return;
                    }
                    File crashFile = new File(crashDir);
                    if (crashFile == null || crashFile.exists() == false) {
                        return;
                    }
                    ArrayList<File> files = new ArrayList<File>();
                    if (crashFile.listFiles() == null || crashFile.listFiles().length == 0) {
                        return;
                    }
                    files.addAll(Arrays.asList(crashFile.listFiles()));
                    if (files.size() == 0) {
                        return;
                    }
                    Collections.sort(files);
                    File file = files.get(files.size() - 1);
                    // String content = FileUtils.read(file.getPath());
                    // MobclickAgent.reportError(instance,
                    // System.currentTimeMillis() + "");
                    String result = HttpClient.postFile(uploadUrl, file);
                    // 1.0.1_2015-06-18_15.txt
                    // result==/app/logs/crash/login.xml
                    if (result != null && result.trim().endsWith(file.getName())) {
                        file.delete();
                    }
                }
            }).start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取邮票列表
     *
     * @param isExpire 是否已过期
     */
    public void couponList(int pageNum, boolean isExpire) {
        Map<String, Object> map = getMap();
        int userId = AppCache.getUserId();
        map.put("userId", userId);
        map.put("pageNum", pageNum);
        int type = isExpire ? 2 : 1;
        map.put("type", type);
        map.put("pageSize", 10);// this.PAGE_SIZE
        //
        HttpReq req = new HttpReq(map, MsgID.couponList + type);
        req.setUrl(getServerUrl() + "findCouponList");// 按照type查询所有的
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取邮票商城列表
     */
    public void stampStoreList() {
        Map<String, Object> map = getMap();
        UserBean userBean = AppCache.getUser();
        if (userBean != null) {
            String phone = userBean.getPhone();
            if (!Str.isEmpty(phone)) {
                map.put("phone", phone);
            }
        }
        map.put("city", AppCache.getCurrentCityName());
        //
        HttpReq req = new HttpReq(map, MsgID.coupon_store);
        req.setUrl(getServerUrl() + "stamp/queryStampShop");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取邮票商城购买记录列表
     */
    public void stampBuyHistoty() {
        Map<String, Object> map = getMap();
        int userId = AppCache.getUserId();
        map.put("userId", userId);
        //
        HttpReq req = new HttpReq(map, MsgID.stamp_history);
        req.setUrl(getServerUrl() + "stamp/queryStampBuyHistory");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取我的失效邮票列表
     */
    public void queryCouponDisableList(int msgID) {
        Map<String, Object> map = getMap();
        int userId = AppCache.getUserId();
        map.put("userId", userId);
        map.put("pageSize", 1000);// this.PAGE_SIZE
        String uri = "stamp/queryStampDisable";// 查询所有的
        HttpReq req = new HttpReq(map, msgID);
        req.setUrl(getServerUrl() + uri);// 根据订单价格查询可用的
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取我的邮票列表
     */
    public void newCouponList(String cost) {
        Map<String, Object> map = getMap();
        int userId = AppCache.getUserId();
        map.put("userId", userId);
        map.put("cost", cost);
        map.put("pageSize", 1000);// this.PAGE_SIZE
        String uri = "stamp/queryStampUsable";// 查询所有的
        if (cost != null) {
            uri = "selectCoupon"; // 根据订单价格查询可用的
        }
        map.put("cost", cost);
        HttpReq req = new HttpReq(map, MsgID.couponList);
        req.setUrl(getServerUrl() + uri);// 根据订单价格查询可用的
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取常用的位置信息
     *
     * @param userId
     */
    public void locationList(int userId) {
        Map<String, Object> map = getMap();
        map.put("userId", userId);
        map.put("pageNum", 1);
        //
        map.put("pageSize", PAGE_SIZE);// this.PAGE_SIZE
        //
        HttpReq req = new HttpReq(map, MsgID.location_list);
        req.setUrl(getServerUrl() + "listAddress");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 删除常用的地址
     *
     * @param addressId
     */
    public void locationDelete(int addressId, int position) {
        Map<String, Object> map = getMap();
        map.put("addressId", addressId);
        //
        HttpReq req = new HttpReq(map, MsgID.location_delete);
        req.setUrl(getServerUrl() + "deleteAddress");
        req.setArg1(position);
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 消息中心 -- 获取消息列表
     */
    public void msgNoticeList(int pageNum) {
        int userId = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("userId", userId);
        map.put("pageNum", 1);
        //
        map.put("pageSize", PAGE_SIZE);// this.PAGE_SIZE
        //
        HttpReq req = new HttpReq(map, MsgID.msg_notice_list);
        req.setUrl(getServerUrl() + "listNotice");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 设置消息通知已读
     */
    public void msgNoticeSetRead() {
        int userId = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("userId", userId);
        //
        HttpReq req = new HttpReq(map, MsgID.msg_notice_updateBatce);
        req.setUrl(getServerUrl() + "updateBatch");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 网点-常用网点列表(收藏的网点列表)
     */
    public void servcePointFavoriteList() {
        UserBean user = AppCache.getUser();
        Map<String, Object> map = getMap();
        map.put("userId", user.getId());
        HttpReq req = new HttpReq(map, MsgID.service_point_favorite_list);
        // req.setUrl(getServerUrl() + "postStation/queryEnshrinePostStationList");
        req.setUrl(getServerUrl() + "stationFavor/queryFavorList");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 网点—通过经纬度查询
     *
     * @param longitude
     * @param latitude
     */
    public void servicePointSearchByLocation(double longitude, double latitude) {
        Map<String, Object> map = getMap();
        // map.put("userId", userId);
        map.put("longitude", longitude);
        map.put("latitude", latitude);
        HttpReq req = new HttpReq(map, MsgID.service_point_search_by_location);
        req.setUrl(getServerUrl() + "station/searchStations");
        // req.setUrl(getServerUrl() + "postStation/searchPostStationList");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 地图模式搜索、目前逻辑跟 {@link #servicePointSearchByLocation(double, double)}一致<br>
     * 暂且分俩方法调用
     *
     * @param longitude
     * @param latitude
     */
    public void servicePointSearchByMap(double longitude, double latitude) {
        Map<String, Object> map = getMap();
        // map.put("userId", userId);
        map.put("longitude", longitude);
        map.put("latitude", latitude);
        HttpReq req = new HttpReq(map, MsgID.service_point_search_by_map);
        req.setUrl(getServerUrl() + "station/searchStations");
        // req.setUrl(getServerUrl() + "postStation/searchPostStationList");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 查询服务网点详情 {@link ServicePointBean}
     *
     * @param type type：1：柜子 2：驿站
     */
    public void servicePointDetails(Object stationId, int type) {
        Map<String, Object> map = getMap();
        UserBean user = AppCache.getUser();
        map.put("userId", user.getId());
        map.put("stationId", stationId);
        map.put("type", type);
        //
        HttpReq req = new HttpReq(map, MsgID.service_point_details_byId);
        req.setUrl(getServerUrl() + "station/queryStationDetail");
        // req.setUrl(getServerUrl() + "postStation/queryPostStationDetail");
        HttpLoader.getInstance().sendReq(req);
    }

    // /**
    // * 收藏网点
    // *
    // * @param type
    // * 1：柜子 2：驿站
    // */
    // public void servicePointFavorite(int stationId, int type) {
    // Map<String, Object> map = getMap();
    // UserBean user = AppCache.getUser();
    // map.put("userId", user.getId());
    // map.put("postStationId", stationId);
    // map.put("type", type);
    // //
    // HttpReq req = new HttpReq(map, MsgID.service_point_favorite_yes);
    // req.setUrl(getServerUrl() + "postStation/saveEnshrinePostBox");
    // HttpLoader.getInstance().sendReq(req);
    // }
    //
    // /**
    // * 收藏网点、取消
    // *
    // * @param type
    // * 1：柜子 2：驿站
    // */
    // public void servicePointFavoriteNo(int enshrineId) {
    // Map<String, Object> map = getMap();
    // map.put("enshrineId", enshrineId);
    // //
    // HttpReq req = new HttpReq(map, MsgID.service_point_favorite_no);
    // req.setUrl(getServerUrl() + "postStation/deleteEnshrinePostBox");
    // HttpLoader.getInstance().sendReq(req);
    // }

    /**
     * 收藏、取消网点
     *
     * @param isFovor 0：取消收藏 1：收藏
     */
    public void servicePointFavorite(int isFovor, int id, String stationCode) {
        Map<String, Object> map = getMap();
        UserBean user = AppCache.getUser();
        map.put("userId", user.getId());
        map.put("isFavor", isFovor);
        map.put("stationId", id);
        map.put("stationCode", stationCode);
        //
        HttpReq req;
        if (isFovor == 1)
            req = new HttpReq(map, MsgID.service_point_favorite_yes);
        else
            req = new HttpReq(map, MsgID.service_point_favorite_no);
        req.setUrl(getServerUrl() + "stationFavor/favor");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 网点—通过关键字查询
     *
     * @param userId
     * @param keyword
     */
    public void findPointByKeyword(String userId, String keyword) {
        Map<String, Object> map = getMap();
        map.put("userId", userId);
        map.put("keyWord", keyword);
        HttpReq req = new HttpReq(map, MsgID.point_list_find_by_keyword);
        req.setUrl(getServerUrl() + "queryPointInfosByKeyWord");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 扫码取货
     *
     * @param cuid
     * @param pointId
     */
    public void scanCodePickUp(String cuid, String guoerUid, String pointId, HttpCallback hcb) {
        Map<String, Object> map = getMap();
        map.put("pointUrl", pointId);
        map.put("guoerUid", guoerUid);
        map.put("cuid", cuid);
        HttpReq req = new HttpReq(map, MsgID.pick_up_scancode, hcb);
        // req.setUrl(getServerUrl() + "scanPick");
        req.setUrl(getServerUrl() + "scanPickForCoupon");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 密码取货
     *
     * @param cuid
     */
    public void passwordPickUp(String cuid, String guoerUid, HttpCallback hcb) {
        Map<String, Object> map = getMap();
        map.put("cuid", cuid);
        map.put("guoerUid", guoerUid);
        HttpReq req = new HttpReq(map, MsgID.pick_up_password, hcb);
        // req.setUrl(getServerUrl() + "pwdPick");
        req.setUrl(getServerUrl() + "pwdPickForCoupon");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取二维码和密码
     *
     * @param cuid
     * @param pointId
     */
    public void getPasswordInfo(String cuid, String guoerUid, String pointId, HttpCallback hcb) {
        Map<String, Object> map = getMap();
        map.put("pointId", pointId);
        map.put("cuid", cuid);
        map.put("guoerUid", guoerUid);
        HttpReq req = new HttpReq(map, MsgID.pick_up_get_password, hcb);
        req.setUrl(getServerUrl() + "passwordInfo");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 微信支付成功的回调 -- 通知服务器修改状态
     *
     * @param outTradeNo
     */
    public void wxPayCallBackForCollect(String outTradeNo) {
        Map<String, Object> map = getMap();
        map.put("outTradeNo", outTradeNo);
        HttpReq req = new HttpReq(map, MsgID.wxPayCallback);
        req.setUrl(getServerUrl() + "collectWeiXinPayCallBack");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 支付宝支付成功的回调 -- 通知服务器修改状态
     *
     * @param outTradeNo
     */
    public void aliPayCallBackForCollect(String outTradeNo) {
        Map<String, Object> map = getMap();
        map.put("outTradeNo", outTradeNo);
        HttpReq req = new HttpReq(map, MsgID.wxPayCallback);
        req.setUrl(getServerUrl() + "collectAliPayCallBack");
        HttpLoader.getInstance().sendReq(req);
    }

    public void getUrl(final String url, int msgId) {
        HttpReq req = new HttpReq(url, null);
        req.setType(HttpLoader.TYPE_TEXT);
        req.setMsgId(msgId);
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 代收评价
     *
     * @param evaluateId
     * @param serviceAttitude
     * @param pointEnvironment
     * @param content
     */
    public void collectEvaluate(String evaluateId, int serviceAttitude, int pointEnvironment, String content) {
        Map<String, Object> map = getMap();
        map.put("evaluateId", evaluateId);
        map.put("serviceAttitude", serviceAttitude);
        map.put("pointEnvironment", pointEnvironment);
        map.put("content", content);

        HttpReq req = new HttpReq(map, MsgID.collect_evaluate);
        req.setUrl(getServerUrl() + "evaluate");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取最新的评价id
     */
    public void queryLatestEvaluateId(int userId, String pointId) {
        Map<String, Object> map = getMap();
        map.put("userId", userId);
        map.put("pointId", pointId);

        HttpReq req = new HttpReq(map, MsgID.collect_query_Latest_EvaluateId);
        req.setUrl(getServerUrl() + "queryLatestEvaluateId");
        HttpLoader.getInstance().sendReq(req);
    }

    /***
     * 获取包裹列表
     *
     */
    public void getParcelList(int type) {
        Map<String, Object> map = getMap();
        UserBean user = AppCache.getUser();
        map.put("userId", AppCache.getUserId());
        map.put("phone", user.getPhone());
        map.put("type", type);
        HttpReq req = null;
        if (type == 0) {// 0-寄件
            req = new HttpReq(map, MsgID.parcel_list_send);
        } else {// 1-收件
            req = new HttpReq(map, MsgID.parcel_list_receive);
        }
        req.setUrl(getServerUrl() + "getMyParcelList");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取我的包裹数量
     */
    public void getParcelCount() {
        Map<String, Object> map = getMap();
        map.put("userId", AppCache.getUserId());
        HttpReq req = new HttpReq(map, MsgID.parcel_count);
        req.setUrl(getServerUrl() + "parcel/queryCount2");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取我的包裹数量
     */
    public void getReceiverParcelCount() {
        Map<String, Object> map = getMap();
        map.put("phone", AppCache.getUser().getPhone());
        HttpReq req = new HttpReq(map, MsgID.receiver_parcel_count);
        req.setUrl(getServerUrl() + "parcel/receiveBagCount");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取寄送包裹列表
     */
    public void getParcelSearchList(String searchKey) {
        Map<String, Object> map = getMap();
        map.put("userId", AppCache.getUserId());
        map.put("phone", searchKey);
        HttpReq req = new HttpReq(map, MsgID.parcel_list_search);
        req.setUrl(getServerUrl() + "parcel/queryByPhone");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取寄送包裹列表
     */
    public void getSendParceListNew(int type, int pageNum, int msgId) {
        Map<String, Object> map = getMap();
        map.put("userId", AppCache.getUserId());
        map.put("pageNum", pageNum);
        map.put("type", type);
        HttpReq req = null;
        req = new HttpReq(map, msgId);
        req.setUrl(getServerUrl() + "parcel/queryList");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取包裹详情
     *
     * @param isCover 是否是补差价  1补差价
     */
    public void getParcelDetailNew(String parcelId, int isCover) {
        Map<String, Object> map = getMap();
        map.put("userId", AppCache.getUserId());
        map.put("parcelId", parcelId);
        map.put("isNeedRepay", isCover);
        HttpReq req = null;
        req = new HttpReq(map, MsgID.parcel_detail);
        req.setUrl(getServerUrl() + "parcel/queryDetail");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * passport详情
     */
    public void getPassportDetail(String parcelId, int position) {
        Map<String, Object> map = getMap();
        map.put("userId", AppCache.getUserId());
        map.put("parcelId", parcelId);
        HttpReq req = new HttpReq(map, MsgID.passport_detail);
        req.setArg1(position);
        req.setUrl(getServerUrl() + "passport/queryDetail350");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * passport代收详情
     */
    public void getPassportCollectingDetail(String stationId, Object takeId) {
        Map<String, Object> map = getMap();
        map.put("userId", AppCache.getUserId());
        map.put("stationId", stationId);
        map.put("takeId", takeId);
        HttpReq req = new HttpReq(map, MsgID.passport_collecting_detail);
        req.setUrl(getServerUrl() + "takeNew/takePassport");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * passport详情中，待揽收状态下，揽收超时用短信提醒火箭侠
     */
    public void sendOuttimeMessage(String parcelId) {
        Map<String, Object> map = getMap();
        map.put("parcelId", parcelId);
        HttpReq req = new HttpReq(map, MsgID.send_out_time_message);
        req.setUrl(getServerUrl() + "passport/noticeCourier");
        HttpLoader.getInstance().sendReq(req);
    }


    /**
     * 重新获取开箱吗
     */
    public void getBoxCode(String parcelId) {
        Map<String, Object> map = getMap();
        map.put("userId", AppCache.getUserId());
        map.put("parcelId", parcelId);
        HttpReq req = null;
        req = new HttpReq(map, MsgID.passport_box_code);
        req.setUrl(getServerUrl() + "box/gege/boxOrderAgain");
        HttpLoader.getInstance().sendReq(req);
    }

    /***
     * 获取包裹详情-发出，收到
     *
     * @param parcelId
     * @param type
     *            0, 寄件包裹详情; 1,收件包裹详情
     */
    public void getParcelDetail(String parcelId, int type) {
        Map<String, Object> map = getMap();
        map.put("orderId", parcelId);
        map.put("type", type);
        HttpReq req = new HttpReq(map, MsgID.parcel_detail_get);
        req.setUrl(getServerUrl() + "getMyParcelDetail");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 包裹电子清单
     *
     * @param orderId
     */
    public void getParcelBill(String orderId) {
        Map<String, Object> map = getMap();
        map.put("userId", AppCache.getUserId());
        map.put("orderId", orderId);
        HttpReq req = new HttpReq(map, MsgID.parcel_bill);
        req.setUrl(getServerUrl() + "passport/queryElectronicWayBill");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * @param orderId
     * @param star       星级
     * @param checkedSet 标签id数组
     * @param content    评价内容
     */
    public void orderEvaluate(String orderId, Float star, HashSet<Integer> checkedSet, String content) {
        UserBean user = AppCache.getUser();
        Map<String, Object> map = getMap();
        map.put("star", star);
        if (checkedSet != null) {
            String tags = checkedSet.toString().replace("[", "").replace("]", "").replace(" ", "");
            map.put("tags", tags);
        }
        map.put("content", content);
        map.put("userId", user.getId());
        map.put("orderId", orderId);

        HttpReq req = new HttpReq(map, MsgID.order_evaluate);
        req.setUrl(getServerUrl() + "evaluate/save");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取评价列表 配置数据
     *
     * @param orderId
     */
    public void orderEvaluateGet(String orderId) {
        UserBean user = AppCache.getUser();
        if (user == null) {
            return;
        }
        Map<String, Object> map = getMap();
        map.put(HttpParam.postText, false);// get请求
        map.put("userId", user.getId());
        map.put("orderId", orderId);
        HttpReq req = new HttpReq(map, MsgID.order_show_evaluate);
        req.setUrl(getServerUrl() + "evaluate/findEvaluateTag");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 扫描驿站二维码、查询当前用户包裹列表
     */
    public void stationGetAllParcels() {
        UserBean user = AppCache.getUser();
        Map<String, Object> map = getMap();
        map.put("userId", user.getId());
        //
        HttpReq req = new HttpReq(map, MsgID.station_getalls);
        req.setUrl(getServerUrl() + "parcel/queryUnDeliverParcels");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 往当前驿站投递包裹
     *
     * @param parcelIds
     * @param stationId
     */
    public void stationPost(String parcelIds, String stationId) {
        parcelIds = parcelIds.replace("[", "").replace("]", "").replace(" ", "");
        Map<String, Object> map = getMap();
        map.put("parcelIds", parcelIds);
        map.put("postStationId", stationId);
        //
        HttpReq req = new HttpReq(map, MsgID.station_post);
        req.setUrl(getServerUrl() + "oneKeyDeliverParcel");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 扫码驿站二维码获取驿站id
     *
     * @param qrCode 二维码的内容
     */
    public void stationGetId(String qrCode) {
        String result = qrCode;
        if (qrCode.indexOf("/") != -1) {
            result = qrCode.substring(qrCode.lastIndexOf("/") + 1);
        }
        Map<String, Object> map = getMap();
        map.put("qrUrlCode", result);
        //
        HttpReq req = new HttpReq(map, MsgID.station_get_id);
        // req.setUrl(getServerUrl() + "station/findAllPostStationByQrUrlCode");
        req.setUrl(getServerUrl() + "station/queryStationIdByQrUrlCode");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 上传身份证认证信息
     *
     * @param name   用户名字
     * @param idCard 用户身份证号
     * @param idImg1 身份证图片地址
     * @param idImg2 身份证图片地址
     */
    public void upLoadIdentityInfo(String name, String idCard, String idImg1, String idImg2) {
        UserBean user = AppCache.getUser();
        Map<String, Object> map = getMap();
        map.put("userId", user.getId());
        map.put("phone", user.getPhone());
        map.put("name", name);
        map.put("idCard", idCard);
        map.put("idImg1", idImg1);
        map.put("idImg2", idImg2);
        HttpReq req = new HttpReq(map, MsgID.identity_info);
        req.setUrl(getServerUrl() + "idCard/submit");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 更新推送的token
     *
     * @param token
     */
    public void updatePushToken(String token) {
        Map<String, Object> map = getMap();
        int userId = AppCache.getUserId();
        map.put("userId", userId);
        map.put("token", token);
        HttpReq req = new HttpReq(map, MsgID.push_token);
        req.setUrl(getServerUrl() + "user/updateToken");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取填写包裹信息中的预支付金额
     *
     * @param destination 收件人地址 省
     * @param source      寄件人地址  市
     * @param weight      包裹重量
     */
    public void getSelfFormPrePayMoney(String source, String destination, String weight) {
        Map<String, Object> map = getMap();
        map.put("source", source);
        map.put("destination", destination);
        map.put("weight", weight);
        if (null != AppCache.getUser()) {
            map.put("userId", AppCache.getUserId());
        }
        HttpReq req = new HttpReq(map, MsgID.get_self_form_prepay_money);
        req.setUrl(getServerUrl() + "order/queryPrice");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 邮票赠送
     */
    public void stampTransform(String phone, String stamp) {
        Map<String, Object> map = getMap();
        int userId = AppCache.getUserId();
        map.put("stampOrderId", stamp);
        map.put("recviverPhone", phone);
        map.put("userId", userId);
        HttpReq req = new HttpReq(map, MsgID.stamp_transform);
        req.setUrl(getServerUrl() + "stamp/present");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取省，市，县
     *
     * @param type 0 获取省  1 获取市  2 获取县
     */
    public void getProvinceCityData(int type, String parentId) {
        Map<String, Object> map = getMap();
        map.put("parentId", parentId);
        int msgId = 0;
        if (type == 1) {
            msgId = MsgID.self_province_city + 1;
        } else if (type == 2) {
            msgId = MsgID.self_province_city + 2;
        } else {
            msgId = MsgID.self_province_city;
        }
        HttpReq req = new HttpReq(map, msgId);
        req.setUrl(getServerUrl() + "queryProvince");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取登录图片验证码
     */
    //    public void getLoginImageCode(String phone) {
    //        Map<String, Object> map = getMap();
    //        map.put("phone", phone);
    //        HttpReq req = new HttpReq(map, MsgID.get_login_image_code);
    //        req.setUrl(getServerUrl() + "code/getImageVerifyCode");
    //        HttpLoader.getInstance().sendReq(req);
    //    }

    /**
     * 邮票分享调用接口
     */
    public void shareWXForStamp(String stampOrderId) {
        Map<String, Object> map = getMap();
        map.put("stampOrderId", stampOrderId);
        map.put("userId", AppCache.getUser().getId());
        HttpReq req = new HttpReq(map, MsgID.share_wx_for_stamp);
        req.setUrl(getServerUrl() + "stamp/shareStamp");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 搜索附近驿站
     */
    public void serachNearStation(String city, String keywords) {
        Map<String, Object> map = getMap();
        map.put("query", keywords);
        map.put("region", city);
        map.put("ak", "Kmwx3Ee8kH6XV3Lsb15LZh64u1Qu4ehN");
        HttpReq req = new HttpReq(map, MsgID.serach_station_for_keywords);
        req.setUrl(getServerUrl() + "station/searchPlace");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 智能填写，服务器返回省市区，电话和姓名
     */
    public void getReceiverInfoParse(String info) {
        Map<String, Object> map = getMap();
        map.put("str", info);
        HttpReq req = new HttpReq(map, MsgID.get_receiver_info_parse);
        req.setUrl(getServerUrl() + "receiver/parseText");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 身份认证状态信息查询
     *
     * @param arg 用于标记哪个类进行接收  0 点击身份认证的时候{@link com.collectplus.express.menu.MenuFragment#onClick(View)}
     *            1 进行包裹揽收的时候{@link com.collectplus.express.parcel.ParcelCheckActivity#onCreate(Bundle)}
     *            2 点击消息进行调用{@link MsgNoticeActivity#findViewById()}
     */
    public void queryIDCardInfo(int arg) {
        Map<String, Object> map = getMap();
        map.put("userId", AppCache.getUserId());
        HttpReq req = new HttpReq(map, MsgID.query_idCard_info);
        req.setArg1(arg);
        req.setUrl(getServerUrl() + "idCard/query");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 启动的时候调用, 获取APP的banner信息
     * int toudi_app = 1;// 火箭投递IOS
     * int lianmeng_app = 2;// 火箭投递安卓
     * int toudi_ios = 4;//火箭联盟IOS
     * int lianmeng_ios = 8; // 火箭联盟安卓
     * int xiaochengxu = 16; // 小程序
     * int stamp_shop = 32;//邮票商场banner
     */
    public void getAppBannerData(int appType) {
        Map<String, Object> map = getMap();
        map.put("city", AppCache.getCurrentCityName());
        map.put("appType", appType);
        HttpReq req = new HttpReq(map, MsgID.get_app_banner_data);
        req.setUrl(getServerUrl() + "queryBanner");
        req.setArg1(appType);
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 根据用户Id获取二维码
     */
    public void getUserQRcode() {
        Map<String, Object> map = getMap();
        map.put("userId", AppCache.getUserId());
        HttpReq req = new HttpReq(map, MsgID.get_user_qrcode);
        req.setUrl(getServerUrl() + "user/getQrCodeUrl");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取上门历史记录数据
     */
    public void getAddressHistoryRecord() {
        Map<String, Object> map = getMap();
        map.put("userId", AppCache.getUserId());
        HttpReq req = new HttpReq(map, MsgID.get_address_history_record);
        req.setUrl(getServerUrl() + "visit/getCommonAddress");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取上门地址
     */
    public void getVisitAddressLocation(double longitude, double latitude) {
        Map<String, Object> map = getMap();
        map.put("longitude", longitude);
        map.put("latitude", latitude);
        HttpReq req = new HttpReq(map, MsgID.visit_address_location);
        req.setUrl(getServerUrl() + "visit/getAddressList");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 搜索地址
     */
    public void serachaddressStation(String city, String keywords) {
        Map<String, Object> map = getMap();
        map.put("query", keywords);
        map.put("region", city);
        map.put("ak", "Kmwx3Ee8kH6XV3Lsb15LZh64u1Qu4ehN");
        HttpReq req = new HttpReq(map, MsgID.serach_address_for_keywords);
        req.setUrl(getServerUrl() + "visit/searchPlace");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 根据坐标查询附近的火箭侠，优惠信息
     *
     * @param type 0 根据经纬度查询附近的火箭侠信息和上门取件的相关信息
     *             1  上门取件界面点击确认选择判断附近是否有可用火箭侠
     */
    public void queryCourierInfoByLocation(int type, double longitude, double latitude) {
        Map<String, Object> map = getMap();
        map.put("longitude", longitude);
        map.put("latitude", latitude);
        int msgId = 0;
        String url = "";
//        if (0 == type) {
        msgId = MsgID.query_courier_info_by_location;
        url = "visit/doorToDoor";
//        } else {
//            msgId = MsgID.is_submit_order_by_location;
//            url = "visit/getAvailableCourier";
//        }
        HttpReq req = new HttpReq(map, msgId);
        req.setUrl(getServerUrl() + url);
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 同城直送初始化起始价，附近火箭侠数量
     */
    public void initCityParcelInfo(double longitude, double latitude, String city) {
        Map<String, Object> map = getMap();
        map.put("longitude", longitude);
        map.put("latitude", latitude);
        map.put("city", city);
        HttpReq req = new HttpReq(map, MsgID.samecity_init_parcel_info);
        req.setUrl(getServerUrl() + "parcel/initCityParcelInfo");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 同城预估价钱和距离，时间
     *
     * @param longitude
     * @param latitude
     * @param city
     */
    public void queryPrePrice(double longitude, double latitude, String city, double targetLongitude, double targetLatitude, Object weight) {
        Map<String, Object> map = getMap();
        map.put("longitude", longitude);
        map.put("latitude", latitude);
        map.put("targetLongitude", targetLongitude);
        map.put("targetLatitude", targetLatitude);
        map.put("city", city);
        map.put("weight", weight);
        HttpReq req = new HttpReq(map, MsgID.samecity_pre_price);
        req.setUrl(getServerUrl() + "order/queryCityGivePrice");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 上门失败后选择驿站投递包裹
     */
    public void queryParcelSendWay(Object orderId, Object id, Object type) {
        Map<String, Object> map = getMap();
        map.put("orderId", orderId);
        map.put("id", id);
        map.put("type", type);
        HttpReq req = new HttpReq(map, MsgID.query_parcel_send_way);
        req.setUrl(getServerUrl() + "parcel/doorToDoor2Station");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取同城历史记录数据
     *
     * @param type 1 寄件人  2 收件人
     */
    public void getAddressHistorySameCity(int type) {
        Map<String, Object> map = getMap();
        map.put("userId", AppCache.getUserId());
        map.put("type", type);
        HttpReq req = new HttpReq(map, MsgID.get_address_history_same_city);
        req.setUrl(getServerUrl() + "cityWide/getCommonAddress");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取同城的地址
     */
    public void getAddressSameCity(double longitude, double latitude) {
        Map<String, Object> map = getMap();
        map.put("longitude", longitude);
        map.put("latitude", latitude);
        HttpReq req = new HttpReq(map, MsgID.same_city_address_location);
        req.setUrl(getServerUrl() + "cityWide/getAddressList");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 同城寄件下单
     */
    public void sameCityOrderSubmit() {
        Map<String, Object> map = getSameCityOrderMap();
        HttpReq req = new HttpReq(map, MsgID.samecity_order_submit);
        req.setUrl(getServerUrl() + "order/reserveOrder2CityGive");
        HttpLoader.getInstance().sendReq(req);
    }

    private HashMap<String, Object> getSameCityOrderMap() {
        UserBean user = AppCache.getUser();
        HashMap<String, Object> map = getMap();
        //同城缓存对象
        SameCityParcelBean item = AppCache.getSameCityParcelBean();
        if (item != null) {
            StringBuilder sb = new StringBuilder();
            sb.append("{");// 最外层{start
            sb.append("'source':1,");
            sb.append("'userId':'").append(user.getId()).append("',");
            sb.append("'phone':'").append(user.getPhone()).append("',");
            sb.append("'payType':'").append(1).append("',");
            // 寄件类型 -- // 0：标准 1：有袋到柜 2：有袋上门 3:有袋到店，驿站  7 同城
            sb.append("'parcelType':").append(Const.ParcelType.sameCityToHome).append(",");
            //包裹详情
            sb.append("'parcels':");
            sb.append("[");// receivers start
            sb.append("{");
            sb.append("'weight':'").append(item.getWeight()).append("',");
            sb.append("'parcelImgUrl':'").append(item.getParcelImgUrl()).append("',");
            sb.append("'comment':'").append(item.getRemark()).append("',");
            sb.append("'category':'").append(item.getGoodsType()).append("',");
            sb.append("}");
            sb.append("]");// receivers end
            sb.append(",");// 注意后面的逗号
            //同城寄件的信息
            sb.append("'receiveCode':'").append(SharedPref.getReceiveCodeBoolean(Constants.SHB_RECEIVE_CODE)).append("',");
            sb.append("'visit':");
            sb.append("{");
            sb.append("'buildName':'").append(item.getSendBuildName()).append("',");
            sb.append("'address':'").append(item.getSendAddress() + item.getSendAddressDesc()).append("',");
            sb.append("'latitude':'").append(item.getSendLatitude()).append("',");
            sb.append("'longitude':'").append(item.getSendLongitude()).append("',");
            sb.append("'addressDesc':'").append(item.getSendAddressDesc()).append("',");
            sb.append("'name':'").append(item.getSendName()).append("',");
            sb.append("'phone':'").append(item.getSendPhone()).append("',");
            sb.append("'province':'").append(item.getSendProvince()).append("',");
            sb.append("'city':'").append(item.getSendCity()).append("',");
            sb.append("'district':'").append(item.getSendDistrict()).append("'");
            sb.append("}");//上门寄件end
            sb.append(",");// 注意后面的逗号
            //同城收件人信息
            sb.append("'targetVisit':");
            sb.append("{");
            sb.append("'buildName':'").append(item.getReceiveBuildName()).append("',");
            sb.append("'address':'").append(item.getReceiveAddress() + item.getReceiveAddressDesc()).append("',");
            sb.append("'latitude':'").append(item.getReceiveLatitude()).append("',");
            sb.append("'longitude':'").append(item.getReceiveLongitude()).append("',");
            sb.append("'addressDesc':'").append(item.getReceiveAddressDesc()).append("',");
            sb.append("'name':'").append(item.getReceiveName()).append("',");
            sb.append("'phone':'").append(item.getReceivePhone()).append("',");
            sb.append("'province':'").append(item.getReceiveProvince()).append("',");
            sb.append("'city':'").append(item.getReceiveCity()).append("',");
            sb.append("'district':'").append(item.getReceiveDistrict()).append("'");
            sb.append("}");//上门寄件end

            sb.append("}");// 最外层}end
            // 过滤掉 'null'字符串 、
            String data = sb.toString().replace("'null'", "null").replace("'", "\"");
            map.put("data", data);
        }
        return map;
    }

    /**
     * 同城根据orderId获取订单详情
     *
     * @param orderId
     */
    public void querySameCityOrderDetail(Object orderId) {
        Map<String, Object> map = getMap();
        map.put("orderId", orderId);
        HttpReq req = new HttpReq(map, MsgID.query_samecity_order_detail);
        req.setUrl(getServerUrl() + "order/getCityUnpayOrderById");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 同城微信支付
     *
     * @param orderId
     * @param realCost 实际支付价格
     */
    public void sameCityWeiXinPay(Object orderId, String cost, String realCost, int couponsId) {
        int userId = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("orderId", orderId);
        map.put("userId", userId);
        map.put("cost", cost);
        map.put("realCost", realCost);
        map.put("openIdType", -1);
        if (couponsId != 0) {
            map.put("couponsId", couponsId);// 邮票
        }
        HttpReq req = new HttpReq(map, MsgID.samecity_weiXinPay);
        req.setUrl(getServerUrl() + "payCityParcel/wxPay");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 同城支付宝支付
     *
     * @param orderId
     * @param realCost 实际支付金额
     */
    public void sameCityAliPay(Object orderId, String cost, String realCost, int couponsId) {
        int userId = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("orderId", orderId);
        map.put("userId", userId);
        map.put("cost", cost);
        map.put("realCost", realCost);
        if (couponsId != 0) {
            map.put("couponsId", couponsId);// 邮票
        }
        HttpReq req = new HttpReq(map, MsgID.samecity_aliPay);
        req.setUrl(getServerUrl() + "payCityParcel/aliPay");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取首页的附近网点信息
     *
     * @param latitude
     * @param longitude
     * @param city
     */
//    public void getHomeNearServicePoint(Object latitude, Object longitude, String city) {
//        Map<String, Object> map = getMap();
//        map.put("latitude", latitude);
//        map.put("longitude", longitude);
//        map.put("city", city);
//        HttpReq req = new HttpReq(map, MsgID.get_home_nearservicepoint);
//        req.setUrl(getServerUrl() + "station/searchNearbyStation");
//        HttpLoader.getInstance().sendReq(req);
//    }

    /**
     * 同城模糊搜索
     *
     * @param keywords 搜索的关键字
     * @param city     搜索的当前城市
     */
    public void serachAddressByKeyWords(Object city, Object keywords) {
        Map<String, Object> map = getMap();
        map.put("query", keywords);
        map.put("region", city);
        map.put("ak", "Kmwx3Ee8kH6XV3Lsb15LZh64u1Qu4ehN");
        HttpReq req = new HttpReq(map, MsgID.samecity_address_by_keywords);
        req.setUrl(getServerUrl() + "cityWide/searchPlace");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取接收包裹在途中包裹列表数据
     */
    public void getReceiverWayParcelList() {
        Map<String, Object> map = getMap();
        map.put("phone", AppCache.getUser().getPhone());
        HttpReq req = new HttpReq(map, MsgID.receiver_parcel_way_list);
        req.setUrl(getServerUrl() + "parcel/wayBags");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取接收包裹已签收包裹列表数据
     */
    public void getReceiverSignedParcelList() {
        Map<String, Object> map = getMap();
        map.put("phone", AppCache.getUser().getPhone());
        HttpReq req = new HttpReq(map, MsgID.receiver_parcel_signed_list);
        req.setUrl(getServerUrl() + "parcel/receiveBags");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 获取接收包裹已签收包裹列表数据
     */
    public void getReceiverReachedStationParcelList() {
        Map<String, Object> map = getMap();
        map.put("phone", AppCache.getUser().getPhone());
        HttpReq req = new HttpReq(map, MsgID.receiver_parcel_reached_station_list);
        req.setUrl(getServerUrl() + "parcel/stationBags");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 接收包裹收取该驿站的全部包裹
     */
    public void receiverPickUpParcelList(Object stationId) {
        Map<String, Object> map = getMap();
        map.put("phone", AppCache.getUser().getPhone());
        map.put("stationId", stationId);
        HttpReq req = new HttpReq(map, MsgID.receiver_parcel_pick_up_data);
        req.setUrl(getServerUrl() + "parcel/pickUp");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 代收包裹列表
     *
     * @param id
     * @param status
     */
    public void getCollectingParcelList(String stationId, int status, Object id) {
        int userId = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("stationId", stationId);
        map.put("userId", userId);
        map.put("status", status);
        map.put("id", id);
        HttpReq req = new HttpReq(map, MsgID.get_collecting_parcel_list);
        req.setUrl(getServerUrl() + "takeNew/takeParcels");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 代收确认取走包裹
     *
     * @param status
     */
    public void confirmCollectingParcelList(String stationId, int status) {
        int userId = AppCache.getUserId();
        Map<String, Object> map = getMap();
        map.put("stationId", stationId);
        map.put("userId", userId);
        map.put("status", status);
        HttpReq req = new HttpReq(map, MsgID.confirm_collecting_parcel_list);
        req.setUrl(getServerUrl() + "takeNew/confirmTake");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 代收在途中包裹详情中确认取走包裹
     *
     * @param parcelId
     */
    public void confirmCollectingParcelDetail(String parcelId) {
        Map<String, Object> map = getMap();
        map.put("parcelId", parcelId);
        HttpReq req = new HttpReq(map, MsgID.confirm_collecting_parcel_detail);
        req.setUrl(getServerUrl() + "parcel/pickUpWay");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 代收---他人代取
     */
    public void otherCollectingParcel(String phone, String stationId) {
        Map<String, Object> map = getMap();
        map.put("phone", phone);
        map.put("stationId", stationId);
        HttpReq req = new HttpReq(map, MsgID.other_collecting_parcel);
        req.setUrl(getServerUrl() + "parcel/collCheckCode");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 投递流程中加快递公司
     */
    public void getSelfExpressCompany(String province, String city, String distrct, double longitude, double latitude) {
        Map<String, Object> map = getMap();
        map.put("province", province);
        map.put("city", city);
        map.put("district", distrct);
        map.put("longitude", longitude);
        map.put("latitude", latitude);
        HttpReq req = new HttpReq(map, MsgID.self_express_company);
        req.setUrl(getServerUrl() + "order/getExpress");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 上门寄件顶部火箭侠的状态
     */
    public void getCourierState(double longitude, double latitude, String cityName, String provinceName, String districtName) {
        Map<String, Object> map = getMap();
        map.put("cityName", cityName);
        map.put("provinceName", provinceName);
        map.put("districtName", districtName);
        map.put("longitude", longitude);
        map.put("latitude", latitude);
        HttpReq req = new HttpReq(map, MsgID.get_courier_state);
        req.setUrl(getServerUrl() + "parcel/couriseCount");
        HttpLoader.getInstance().sendReq(req);
    }

    /**
     * 计算价格初始化价格
     *
     * @param longitude
     * @param latitude
     * @param weight
     * @param source      寄件人的市
     * @param destination 收件人的省
     * @param parcelType  6 上门  7 同城
     */
    public void initCalculatePrice(double longitude, double latitude, Object weight, int parcelType, String source, String destination, double targetLongitude, double targetLatitude) {
        Map<String, Object> map = getMap();
        map.put("longitude", longitude);
        map.put("latitude", latitude);
        map.put("weight", weight);
        map.put("parcelType", parcelType);
        map.put("source", source);
        map.put("destination", destination);
        map.put("targetLongitude", targetLongitude);
        map.put("targetLatitude", targetLatitude);
        HttpReq req = new HttpReq(map, MsgID.init_calculate_price);
        req.setUrl(getServerUrl() + "order/computePrice");
        HttpLoader.getInstance().sendReq(req);
    }
}
